var t = require;
var e = module;
var o = exports;
var a =
    (this && this.__decorate) ||
    function (t, e, o, a) {
        var i,
            n = arguments.length,
            r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
        else
            for (var s = t.length - 1; s >= 0; s--)
                (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
        return n > 3 && r && Object.defineProperty(e, o, r), r;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var i = cc._decorator.ccclass,
    n = new ((function () {
        function t() {
            this.bn = { Res: "Res", Res2: "Res2", Res3: "Res3" };
            this._bundle = {};
            this.spriteCache = {};
        }
        t.prototype.loadRes = function (t, e, o, a) {
            this.checkGetBundle(t, function (t) {
                var i = t.get(e, o);
                i ? a && a(null, i) : t.load(e, o, a);
            });
        };
        t.prototype.loadResUnError = function (t, e, o, a) {
            this.checkGetBundle(t, function (i) {
                var n = i.get(e, o);
                n
                    ? a && a(n)
                    : i.load(e, o, function (o, i) {
                        o && cc.error(o, t, e);
                        a && a(i);
                    });
            });
        };
        t.prototype.preloadBundle = function (t, e) {
            cc.assetManager.loadBundle(t, function (t) {
                e && e();
                t && cc.error(t);
            });
        };
        t.prototype.checkGetBundle = function (t, e) {
            var o = this;
            this._bundle[t]
                ? e && e(this._bundle[t])
                : cc.assetManager.loadBundle(t, function (a, i) {
                    if (a) cc.log(t + " bundle 获取失败", a);
                    else {
                        o._bundle[t] = i;
                        e && e(o._bundle[t]);
                    }
                });
        };
        t.prototype.setSprite = function (t, e, o, a, i) {
            void 0 === a && (a = !0);
            var n;
            if (!a) {
                (n = cc.Vec2.ZERO).x = o.node.width;
                n.y = o.node.height;
            }
            this.getCacheSpriteFramer(
                t,
                e,
                function (t) {
                    if (cc.isValid(o)) {
                        o.spriteFrame = t;
                        if (n) {
                            o.node.width = n.x;
                            o.node.height = n.y;
                        }
                    }
                },
                i
            );
        };
        t.prototype.setSpriteAtlasCache = function (t, e) {
            var o = this;
            if (!this.spriteCache[t + "/" + e]) {
                var a = "" + e;
                this.checkGetBundle(t, function (i) {
                    i.load(a, cc.SpriteAtlas, function (a, i) {
                        a || (o.spriteCache[t + "/" + e] = i);
                    });
                });
            }
        };
        t.prototype.setSpriteAtlas2 = function (t, e, o, a, i, n) {
            var r,
                s = this;
            void 0 === i && (i = !0);
            if (!i) {
                (r = cc.Vec2.ZERO).x = a.node.width;
                r.y = a.node.height;
            }
            if (this.spriteCache[t + "/" + e]) {
                if (this.spriteCache[t + "/" + e]) {
                    var c = this.spriteCache[t + "/" + e].getSpriteFrame(o);
                    this.toSpriteSpf(a, c);
                    if (r) {
                        a.node.width = r.x;
                        a.node.height = r.y;
                    }
                }
                n && n();
            } else {
                var p = "" + e;
                this.checkGetBundle(t, function (i) {
                    i.load(p, cc.SpriteAtlas, function (i, c) {
                        if (!i) {
                            s.spriteCache[t + "/" + e] = c;
                            if (s.spriteCache[t + "/" + e]) {
                                var p = s.spriteCache[t + "/" + e].getSpriteFrame(o);
                                s.toSpriteSpf(a, p);
                                if (r) {
                                    a.node.width = r.x;
                                    a.node.height = r.y;
                                }
                            }
                        }
                        n && n();
                    });
                });
            }
        };
        t.prototype.setSpriteAtlas = function (t, e, o, a, i, n) {
            var r,
                s = this;
            void 0 === i && (i = !0);
            if (!i) {
                (r = cc.Vec2.ZERO).x = a.node.width;
                r.y = a.node.height;
            }
            if (this.spriteCache[t + "/" + e]) {
                if (this.spriteCache[t + "/" + e]) {
                    var c = this.spriteCache[t + "/" + e].getSpriteFrame(o);
                    this.toSpriteSpf(a, c);
                    if (c) {
                        a.node.width = c.getRect().width;
                        a.node.height = c.getRect().height;
                    }
                }
                n && n();
            } else {
                var p = "" + e;
                this.checkGetBundle(t, function (i) {
                    i.load(p, cc.SpriteAtlas, function (i, r) {
                        if (!i) {
                            s.spriteCache[t + "/" + e] = r;
                            if (s.spriteCache[t + "/" + e]) {
                                var c = s.spriteCache[t + "/" + e].getSpriteFrame(o);
                                s.toSpriteSpf(a, c);
                                if (c) {
                                    a.node.width = c.getRect().width;
                                    a.node.height = c.getRect().height;
                                }
                            }
                        }
                        n && n();
                    });
                });
            }
        };
        t.prototype.toSpriteSpf = function (t, e) {
            cc.isValid(t) && (t.spriteFrame = e);
        };
        t.prototype.getCacheSpriteFramer = function (t, e, o, a) {
            var i = this;
            if (this.spriteCache[t + "/" + e]) {
                o && o(this.spriteCache[t + "/" + e]);
                a && a();
            } else {
                var n = "" + e;
                this.checkGetBundle(t, function (r) {
                    r.load(n, cc.Texture2D, function (n, r) {
                        if (!n) {
                            i.spriteCache[t + "/" + e] = new cc.SpriteFrame(r);
                            o && o(i.spriteCache[t + "/" + e]);
                        }
                        a && a();
                    });
                });
            }
        };
        t.prototype.getSpriteTexture2D = function (t, e, o, a) {
            var i = "" + e;
            this.checkGetBundle(t, function (t) {
                t.load(i, cc.Texture2D, function (t, e) {
                    t || (o && o(Object.create(e)));
                    a && a();
                });
            });
        };
        t.prototype.getRes = function (t, e, o) {
            var a;
            "/" != e[0] && (e = "/" + e);
            return null === (a = cc.assetManager.getBundle(t)) || void 0 === a ? void 0 : a.get(e, o);
        };
        t.prototype.loadSpriteFrameUnError = function (t, e, o) {
            this.loadTextureUnError(t, e, function (t) {
                o && o(new cc.SpriteFrame(t));
            });
        };
        t.prototype.loadTextureUnError = function (t, e, o) {
            var a = "" + e;
            this.checkGetBundle(t, function (t) {
                t.load(a, cc.Texture2D, function (t, e) {
                    t && cc.error(t);
                    o && o(e);
                });
            });
        };
        return a([i], t);
    })())();
window.BundleManager = n;
o.default = n;
